package cms.com.yh.contorller;

import cms.common.CodeMsg;
import cms.common.Result;
import cms.mager.domain.User;
import cms.mager.service.UserService;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName: CheckCodeController.java
 * @author: yuhui
 * @version: 1.0.0
 * @Description: TODO
 * @createTime: 2021年04月20日 01:11:00
 */
@Controller
@RequestMapping("checkCode")
public class CheckCodeController {
    @Autowired
    private UserService us;
    /**
     * 功能描述: 生成验证码
     * @Author: yuhui  2021/4/8 18:02
     */
    @RequestMapping("create.do")
    private void createCheckCode(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //createLineCaptcha(宽度,高度,字符个数,干扰元素个数)
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 6);
        //验证码图片中字符串 验证码字符串
        String code = lineCaptcha.getCode();
        req.getSession().setAttribute("code",code);
        Result re = new Result(code);
        resp.getWriter().print(JSONObject.toJSONString(re));

    }

}
